import json

def dump_list_of_dicts_to_json(data, file_path):
    with open(file_path, 'w', encoding='utf-8') as json_file:
        json.dump(data, json_file, ensure_ascii=False, indent=4)

# Example usage
rules = {
    "function_definition":
    [
        {
            "condition":
            {
                "parent": "node.parent.type == 'translation_unit'",
                "siblings": "",
                "children": "",
                "other_conditions_judge_function": ""
            }
        }
    ],
    "compound_statement":
    [
        {
            "condition":
            {
                "parent": "node.parent.type == 'function_definition'",
                "siblings": "",
                "children": "",
                "other_conditions_judge_function": "any(child.type == 'function_declarator' and any(grandchild.type == 'identifier' and grandchild.text == b'main' for grandchild in child.named_children) for child in node.named_children)"
            }
        }
    ]
}


file_path = '/disk1/wyf/Project/zz_static_project/src/data_augmentation/rules/output.json'
dump_list_of_dicts_to_json(rules, file_path)


# rules = {
#     "function_definition":
#     [
#         {
#             "condition":
#             {
#                 "parent": "node.parent.type == 'translation_unit'",
#                 "siblings": "",
#                 "children": "",
#                 "other_conditions_judge_function": ""
#             },
#             "insert_position":
#             [
#                 {
#                     "position": "prev_sibling",
#                     "nodes": 
#                     [
#                         "function_definition"
#                     ]
#                 },
#                 {
#                     "position": "next_sibling",
#                     "nodes": 
#                     [
#                         "function_definition"
#                     ]
#                 }
#             ]
#         }
#     ],
#     "compound_statement":
#     [
#         {
#             "condition":
#             {
#                 "parent": "node.parent.type == 'function_definition'",
#                 "siblings": "",
#                 "children": "",
#                 "other_conditions_judge_function": "any(child.type == 'function_declarator' and any(grandchild.type == 'identifier' and grandchild.text == b'main' for grandchild in child.named_children) for child in node.named_children)"
#             },
#             "insert_position":
#             [
#                 {
#                     "position": "left_child",
#                     "nodes":
#                     [
#                         "assignment_expression",
#                         "switch_statement",
#                         "while_statement",
#                         "if_statement",
#                         "compound_statement"
#                     ]
#                 }
#             ]
#         }
#     ]
# }